package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huifaapp.mall.R;

import java.util.List;

/**
 * Created by duanyu on 2017/12/21.
 */

public class PopuplayoutColourapter extends  RecyclerView.Adapter<PopuplayoutColourapter.ColourViewHolder>implements View.OnClickListener  {
    private List<String>Colourlist;
    private Context Context;

    public PopuplayoutColourapter(List<String> colourlist, android.content.Context context) {
        Colourlist = colourlist;
        Context = context;
    }

    @Override
    public PopuplayoutColourapter.ColourViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View holder = LayoutInflater.from(parent.getContext()).inflate(R.layout.itme_popuplayout_colouradapter, parent, false);
        holder.setOnClickListener(this);
        return new ColourViewHolder(holder);
    }

    @Override
    public void onBindViewHolder(PopuplayoutColourapter.ColourViewHolder holder, int position) {
          holder.colourtext.setText(Colourlist.get(position));
        holder.itemView.setTag(position);
    }
    public interface MyColourItemclickListener {
        void Colouritemclick(View view, int position);
    }
    public PopuplayoutColourapter.MyColourItemclickListener mMyColourItemclickListener;

    public void setmMyItemclickListener(PopuplayoutColourapter.MyColourItemclickListener mMyColourItemclickListener) {
        this.mMyColourItemclickListener = mMyColourItemclickListener;
    }

    @Override
    public int getItemCount() {
        return Colourlist.size();
    }

    @Override
    public void onClick(View v) {
        if (mMyColourItemclickListener != null) {
            mMyColourItemclickListener.Colouritemclick(v, (Integer) v.getTag());
        }
    }
    class ColourViewHolder extends RecyclerView.ViewHolder {

        private final TextView colourtext;

        public ColourViewHolder(View itemView) {
            super(itemView);
            colourtext = (TextView) itemView.findViewById(R.id.Colourtext);
        }
    }
}
